//Modify all structures to class to define 
//destructors
#pragma once
#include <vector>
#include <map>
#include <set>
#include <string>

#define MAJOR_VERSION 1
#define MINOR_VERSION 0

struct station;
struct connection;
class  ctrain;
class  crouteplan;

typedef std::pair<int, ctrain*>		train_pair;
typedef std::pair<connection, int>	path;
typedef std::map<connection, int>	route;   //int just lenght
typedef std::vector<station>		train_plan;
typedef route::iterator			    route_iterator;
typedef std::map<int, ctrain*>		trainset;
typedef trainset::iterator		    train_iterator;




struct station{
	int  id;
//  char * name;
};

struct connection{
	station source;
	station destination;

	connection(){};
	connection(station st1, station st2) : source(st1),destination(st2){}

	bool operator <  (const connection &) const;
	bool operator == (const connection &) const;
};

class crouteplan{

	route * m_route;

	void search_shortest_connection();
public:
	crouteplan();
	~crouteplan();

	void loadconfiguration(connection &, int);
	int  get_lenght(const connection &);
	int  get_lenght(station &, station &);
	void get_new_path(connection &);
};

class ctrain{
	crouteplan * m_route;
	train_plan * m_plan;
	path         m_current_path; //this is const for whole path (not route)
	int          m_train_id;
	unsigned int m_index_route;
	int          m_last_position;
	int          m_curr_position;
	int          m_speed;
	bool         m_end_road;
public:
	ctrain(int id);
	~ctrain();
	void make_step();
	void add_station(station &);
	void init_train(crouteplan &);
	void init_train();
	bool is_collision(const ctrain *) const;
	bool is_finish(){return m_end_road;};
};


class crailway{

	crouteplan  m_routeplan; //we have a one routeplan
	trainset    m_trainset;

public:

	crailway();
	~crailway();

	void checkcollisions();
	void addtrainconfig(int, station &);
	void loadconfiguration(char *);
	void set_route_map(std::string &);
	void set_train_plan(std::string &);
	void init_trains();
	void check_collision();
	void simulate_trains();
};
